﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Wicresoft.EKA.MVCExtensions;
using Wicresoft.EKA.ITSM.Business;
using Ninject;



namespace Wicresoft.EKA.ITSM.Web.WebPortal.Controllers
{
    public class InspectionRuleAPIController : BaseAPIController  
    {
        [Inject]
        public ISMGXJPlanObject SMGXJPlanObject { get; set; }

        [Inject]
        public ISMGXJPlanRule SMGXJPlanRule { get; set; }

        [Inject]
        public override IUserInfo UserInfo { get; set; }  //每个Controller必须包含的。

        protected override void Init()
        {
            ((IBase)SMGXJPlanObject).UserIdentify = UserName;
            ((IBase)SMGXJPlanRule).UserIdentify = UserName;
            base.Init();
        }

        protected override void Dispose(bool disposing)
        {
            ((IBase)SMGXJPlanObject).Dispose();
            ((IBase)SMGXJPlanRule).Dispose();
            base.Dispose(disposing);
        }
        
        //获取Rule列表
        public object GetRule(string Type,string Permission)
        {
            Init();
            string Qual = "'cChr_Char03'=\"" + Type + "\" AND ('cChr_Permission' = \"" + Permission + "\" OR 'cChr_Permission' = \"Public\")";
            return SMGXJPlanRule.GetList(Qual);
        }

        //新建Rule
        public object Post(string type,string Permission,[FromBody] SMGXJPlanRuleModel model)
        {
            Init();
            model.Submitter = UserName;
            model.ShortDescription = "Create";
            model.cChr_Char03 = type;
            model.cChr_Permission = Permission;
            if (model.cChr_RuleType == "Input") model.cChr_RuleValue = null;
            return SMGXJPlanRule.Create(model);
        }

        //?
        public object Put(string id, [FromBody] SMGXJPlanRuleModel model)
        {
            Init();
            string Qual = "\'Request ID\' =\"" + id + "\"";
            return SMGXJPlanRule.Modify(model, Qual);
        }

        public object GetToModify(string requestid)
        {
            Init();
            return "Success";
            //SMGXJPlanRuleModel model = new SMGXJPlanRuleModel();
            //model.ShortDescription = "modify";
            //model.Submitter = UserName;
            //model.cChr_RuleName = name;
            //model.cChr_RuleType = type;
            //model.cChr_Threshold = fazhi;
            //model.cChr_RuleValue = value;
            //string Qual = "\'Request ID\' =\"" + requestid + "\"";
            //return SMGXJPlanRule.Modify(model, Qual);

        }
    }
}